<html>
<head>
<title>AbilityGlobalDataSyncCode.ets</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #808080;}
.s1 { color: #a9b7c6;}
.s2 { color: #aa7dfc;}
.s3 { color: #e2da90;}
.s4 { color: #faa23d;}
.s5 { color: #bbb529;}
.s6 { color: #b3e54c;}
.s7 { color: #db7e9b;}
</style>
</head>
<body bgcolor="#2b2b2b">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
AbilityGlobalDataSyncCode.ets</font>
</center></td></tr></table>
<pre><span class="s0">/* 
 * Copyright (c) 2023 Huawei Device Co., Ltd. 
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an &quot;AS IS&quot; BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */</span>

<span class="s1">import router from </span><span class="s2">'@ohos.router'</span><span class="s3">;</span>
<span class="s1">import </span><span class="s4">{ </span><span class="s1">ViewCodeText </span><span class="s4">} </span><span class="s1">from </span><span class="s2">'../../../commoncomponents/ViewCodeText'</span><span class="s3">;</span>
<span class="s1">import </span><span class="s4">{ </span><span class="s1">startSpecifiedAbility </span><span class="s4">} </span><span class="s1">from </span><span class="s2">'../model/CommonMethods'</span><span class="s3">;</span>

<span class="s5">@</span><span class="s1">Component</span>
<span class="s1">export struct AbilityGlobalDataSyncCode </span><span class="s4">{</span>
  <span class="s0">// 初始化Slider最小值</span>
  <span class="s1">private minFontSize</span><span class="s3">: </span><span class="s1">number </span><span class="s3">= </span><span class="s6">10</span><span class="s3">;</span>
  <span class="s0">// 和主页、Page1、Page2双向同步内容字体大小</span>
  <span class="s5">@</span><span class="s1">LocalStorageLink</span><span class="s7">(</span><span class="s2">'contentFontSize'</span><span class="s7">) </span><span class="s1">contentFontSize</span><span class="s3">: </span><span class="s1">number </span><span class="s3">= </span><span class="s6">18</span><span class="s3">;</span>
  <span class="s0">// 和主页、Page1、Page2双向同步夜间模式状态</span>
  <span class="s5">@</span><span class="s1">LocalStorageLink</span><span class="s7">(</span><span class="s2">'currentModelStatus'</span><span class="s7">) </span><span class="s1">currentModelStatus</span><span class="s3">: </span><span class="s1">boolean </span><span class="s3">= </span><span class="s1">true</span><span class="s3">;</span>

  <span class="s1">build</span><span class="s7">() </span><span class="s4">{</span>
    <span class="s1">Column</span><span class="s7">(</span><span class="s4">{ </span><span class="s1">space</span><span class="s3">: </span><span class="s6">10 </span><span class="s4">}</span><span class="s7">) </span><span class="s4">{</span>
      <span class="s0">// 查看源码</span>
      <span class="s1">ViewCodeText</span><span class="s7">(</span><span class="s4">{ </span><span class="s1">webSrc</span><span class="s3">: </span><span class="s1">$rawfile</span><span class="s7">(</span><span class="s2">'AbilityGlobalDataSyncCode.ets.html'</span><span class="s7">) </span><span class="s4">}</span><span class="s7">)</span>
      <span class="s1">Row</span><span class="s7">() </span><span class="s4">{</span>
        <span class="s1">Text</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.string.nightmode'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.tips_font_color'</span><span class="s7">))</span>
        <span class="s0">// 控制夜间模式</span>
        <span class="s1">Toggle</span><span class="s7">(</span><span class="s4">{ </span><span class="s1">type</span><span class="s3">: </span><span class="s1">ToggleType</span><span class="s3">.</span><span class="s1">Switch</span><span class="s3">, </span><span class="s1">isOn</span><span class="s3">: </span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s4">}</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">selectedColor</span><span class="s7">(</span><span class="s1">Color</span><span class="s3">.</span><span class="s1">Blue</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">switchPointColor</span><span class="s7">(</span><span class="s1">Color</span><span class="s3">.</span><span class="s1">White</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">onChange</span><span class="s7">((</span><span class="s1">isOn</span><span class="s3">: </span><span class="s1">boolean</span><span class="s7">) </span><span class="s3">=&gt; </span><span class="s4">{</span>
            <span class="s0">// 更新控制夜间模式状态的变量数据，@StorageLink和@StorageLink关联的数据变量刷新</span>
            <span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">= </span><span class="s1">isOn</span><span class="s3">;</span>
          <span class="s4">}</span><span class="s7">)</span>
      <span class="s4">}</span><span class="s3">.</span><span class="s1">justifyContent</span><span class="s7">(</span><span class="s1">FlexAlign</span><span class="s3">.</span><span class="s1">SpaceAround</span><span class="s7">)</span>
      <span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'70%'</span><span class="s7">)</span>
      <span class="s3">.</span><span class="s1">border</span><span class="s7">(</span><span class="s4">{ </span><span class="s1">radius</span><span class="s3">: </span><span class="s6">50</span><span class="s3">, </span><span class="s1">color</span><span class="s3">: </span><span class="s1">Color</span><span class="s3">.</span><span class="s1">Grey</span><span class="s3">, </span><span class="s1">width</span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.float.border_width'</span><span class="s7">) </span><span class="s4">}</span><span class="s7">)</span>

      <span class="s1">Text</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.string.ability_storage_nightmodelsync'</span><span class="s7">))</span>
        <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s7">)</span>
        <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.tips_font_color'</span><span class="s7">))</span>
        <span class="s3">.</span><span class="s1">textAlign</span><span class="s7">(</span><span class="s1">TextAlign</span><span class="s3">.</span><span class="s1">Center</span><span class="s7">)</span>
      <span class="s0">// slider滑动模块控制字体大小</span>
      <span class="s1">Column</span><span class="s7">() </span><span class="s4">{</span>
        <span class="s1">Text</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.string.fontSize_text'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.tips_font_color'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'100%'</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">textAlign</span><span class="s7">(</span><span class="s1">TextAlign</span><span class="s3">.</span><span class="s1">Center</span><span class="s7">)</span>
        <span class="s1">Row</span><span class="s7">() </span><span class="s4">{</span>
          <span class="s1">Text</span><span class="s7">(</span><span class="s2">`</span><span class="s4">${</span><span class="s1">this</span><span class="s3">.</span><span class="s1">minFontSize</span><span class="s4">}</span><span class="s2">`</span><span class="s7">)</span>
            <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.tips_font_color'</span><span class="s7">))</span>
            <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.float.tips_font_size'</span><span class="s7">))</span>
          <span class="s1">Slider</span><span class="s7">(</span><span class="s4">{</span>
            <span class="s1">value</span><span class="s3">: </span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s3">,</span>
            <span class="s1">min</span><span class="s3">: </span><span class="s6">10</span><span class="s3">, </span><span class="s0">// slider最小值</span>
            <span class="s1">max</span><span class="s3">: </span><span class="s6">30</span><span class="s3">, </span><span class="s0">// slider最大值</span>
            <span class="s1">style</span><span class="s3">: </span><span class="s1">SliderStyle</span><span class="s3">.</span><span class="s1">OutSet</span>
          <span class="s4">}</span><span class="s7">)</span>
            <span class="s3">.</span><span class="s1">showTips</span><span class="s7">(</span><span class="s1">true</span><span class="s7">)</span>
            <span class="s3">.</span><span class="s1">onChange</span><span class="s7">((</span><span class="s1">value</span><span class="s3">: </span><span class="s1">number</span><span class="s3">, </span><span class="s1">mode</span><span class="s3">: </span><span class="s1">SliderChangeMode</span><span class="s7">) </span><span class="s3">=&gt; </span><span class="s4">{</span>
              <span class="s0">// 更新控制字体大小状态的变量数据，@LocalStorageLink和@LocalStorageProp关联的数据变量刷新</span>
              <span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize </span><span class="s3">= </span><span class="s1">value</span><span class="s3">;</span>
            <span class="s4">}</span><span class="s7">)</span>
          <span class="s0">// toFixed(0)将滑动条返回值处理为整数精度</span>
          <span class="s1">Text</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s3">.</span><span class="s1">toFixed</span><span class="s7">(</span><span class="s6">0</span><span class="s7">))</span>
            <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.tips_font_color'</span><span class="s7">))</span>
            <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.float.tips_font_size'</span><span class="s7">))</span>
        <span class="s4">}</span>
        <span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'80%'</span><span class="s7">)</span>
      <span class="s4">}</span><span class="s3">.</span><span class="s1">margin</span><span class="s7">(</span><span class="s4">{ </span><span class="s1">top</span><span class="s3">: </span><span class="s6">50 </span><span class="s4">}</span><span class="s7">)</span>

      <span class="s1">Text</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.string.ability_storage_fontsizesync'</span><span class="s7">))</span>
        <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s7">)</span>
        <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.tips_font_color'</span><span class="s7">))</span>
        <span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'100%'</span><span class="s7">)</span>
        <span class="s3">.</span><span class="s1">textAlign</span><span class="s7">(</span><span class="s1">TextAlign</span><span class="s3">.</span><span class="s1">Center</span><span class="s7">)</span>
      <span class="s1">Button</span><span class="s7">() </span><span class="s4">{</span>
        <span class="s1">Text</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.string.enter_pageone'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.button_text_color'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'60%'</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">textAlign</span><span class="s7">(</span><span class="s1">TextAlign</span><span class="s3">.</span><span class="s1">Center</span><span class="s7">)</span>
      <span class="s4">}</span>
      <span class="s3">.</span><span class="s1">type</span><span class="s7">(</span><span class="s1">ButtonType</span><span class="s3">.</span><span class="s1">Capsule</span><span class="s7">)</span>
      <span class="s3">.</span><span class="s1">backgroundColor</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.button_background_color'</span><span class="s7">))</span>
      <span class="s3">.</span><span class="s1">padding</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.float.page_padding'</span><span class="s7">))</span>
      <span class="s3">.</span><span class="s1">onClick</span><span class="s7">(() </span><span class="s3">=&gt; </span><span class="s4">{</span>
        <span class="s1">router</span><span class="s3">.</span><span class="s1">pushUrl</span><span class="s7">(</span><span class="s4">{ </span><span class="s1">url</span><span class="s3">: </span><span class="s2">'pages/applylevelstagemanagement/abilityglobaldatasync/LocalStoragePropPage' </span><span class="s4">}</span><span class="s7">)</span><span class="s3">;</span>
      <span class="s4">}</span><span class="s7">)</span>

      <span class="s1">Button</span><span class="s7">() </span><span class="s4">{</span>
        <span class="s1">Text</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.string.enter_pagetwo'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.button_text_color'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'60%'</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">textAlign</span><span class="s7">(</span><span class="s1">TextAlign</span><span class="s3">.</span><span class="s1">Center</span><span class="s7">)</span>
      <span class="s4">}</span>
      <span class="s3">.</span><span class="s1">type</span><span class="s7">(</span><span class="s1">ButtonType</span><span class="s3">.</span><span class="s1">Capsule</span><span class="s7">)</span>
      <span class="s3">.</span><span class="s1">backgroundColor</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.button_background_color'</span><span class="s7">))</span>
      <span class="s3">.</span><span class="s1">padding</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.float.page_padding'</span><span class="s7">))</span>
      <span class="s3">.</span><span class="s1">onClick</span><span class="s7">(() </span><span class="s3">=&gt; </span><span class="s4">{</span>
        <span class="s1">router</span><span class="s3">.</span><span class="s1">pushUrl</span><span class="s7">(</span><span class="s4">{ </span><span class="s1">url</span><span class="s3">: </span><span class="s2">'pages/applylevelstagemanagement/abilityglobaldatasync/LocalStorageLinkPage' </span><span class="s4">}</span><span class="s7">)</span><span class="s3">;</span>
      <span class="s4">}</span><span class="s7">)</span>

      <span class="s1">Divider</span><span class="s7">()</span><span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'100%'</span><span class="s7">)</span><span class="s3">.</span><span class="s1">strokeWidth</span><span class="s7">(</span><span class="s6">1</span><span class="s7">)</span>
      <span class="s1">Button</span><span class="s7">() </span><span class="s4">{</span>
        <span class="s1">Text</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.string.enter_ability_outofsync'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">fontColor</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">currentModelStatus </span><span class="s3">? </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.color_white'</span><span class="s7">) </span><span class="s3">: </span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.button_text_color'</span><span class="s7">))</span>
          <span class="s3">.</span><span class="s1">fontSize</span><span class="s7">(</span><span class="s1">this</span><span class="s3">.</span><span class="s1">contentFontSize</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'60%'</span><span class="s7">)</span>
          <span class="s3">.</span><span class="s1">textAlign</span><span class="s7">(</span><span class="s1">TextAlign</span><span class="s3">.</span><span class="s1">Center</span><span class="s7">)</span>
      <span class="s4">}</span>
      <span class="s3">.</span><span class="s1">type</span><span class="s7">(</span><span class="s1">ButtonType</span><span class="s3">.</span><span class="s1">Capsule</span><span class="s7">)</span>
      <span class="s3">.</span><span class="s1">backgroundColor</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.color.button_background_color'</span><span class="s7">))</span>
      <span class="s3">.</span><span class="s1">padding</span><span class="s7">(</span><span class="s1">$r</span><span class="s7">(</span><span class="s2">'app.float.page_padding'</span><span class="s7">))</span>
      <span class="s3">.</span><span class="s1">onClick</span><span class="s7">(() </span><span class="s3">=&gt; </span><span class="s4">{</span>
        <span class="s1">startSpecifiedAbility</span><span class="s7">(</span><span class="s2">'OutOfSyncAbility'</span><span class="s7">)</span><span class="s3">;</span>
      <span class="s4">}</span><span class="s7">)</span>
    <span class="s4">}</span>
    <span class="s3">.</span><span class="s1">width</span><span class="s7">(</span><span class="s2">'100%'</span><span class="s7">)</span>
    <span class="s3">.</span><span class="s1">padding</span><span class="s7">(</span><span class="s6">10</span><span class="s7">)</span>
  <span class="s4">}</span>
<span class="s4">}</span></pre>
</body>
</html>